#define DEBUG
#include <cstdio>

using namespace std;

typedef long long ll;

const int maxn=262144, mods=998244353, g=3;

int logt[maxn+1];

int max(int a, int b) {
  return a>b ? a : b;
}

void initLogt(int n) {
  for (int i=2; i<=n; i++) {
    logt[i] = logt[(i+1)/2]+1;
  }
}

ll qpower(ll a, int n) {
  ll s=1;
  for (; n>1; n/=2) {
    if (n&1) {
      s = s*a%mods;
    }
    a = a*a%mods;
  }
  return s*a%mods;
}

ll getOmega(int n) {
  return qpower(g, (mods-1)/n);
}

class Poly {
public:
  //a[n] has value.
  int n, a[maxn+1];
  bool flag=false;

  Poly& cpy(const Poly &x) {
    n = x.n;
    for (int i=0; i<=n; i++) a[i] = x.a[i];
    return *this;
  }

  Poly& revert() {
    for (int i=0; i<=(n-1)/2; i++) {
      int t;
      t=a[i], a[i]=a[n-i], a[n-i]=t;
    }
    return *this;
  }

  Poly& ntt(int nt=0) {
    static int pos[maxn+1];
    n = 1<<logt[(nt ? nt : n)+1];
    int len = logt[n]-1;
    for (int i=0, t; i<n; i++) {
      pos[i] = pos[i>>1] | ((i&1)<<len);
      if (pos[i]>i) t=a[i], a[i]=a[pos[i]], a[pos[i]]=t;
    }

    for (int len=0; (1<<len)<n; len++) {
      ll w=getOmega(len);
      if (flag) w = qpower(w, mods-2);
      for (int i=0; i<n; i+=len*2) {
        ll t=1;
        for (int j=0; j<len; j++) {
          ll x=a[i+j], y=t*a[i+len+j]%mods;
          a[i+j] = (x+y)%mods;
          a[i+len+j] = (x+mods-y)%mods;
          t = t*w%mods;
        }
      }
    }
    
    if (flag) {
      ll ni = qpower(n, mods-2);
      for (int i=0; i<n; i++) {
        a[i] = a[i]*ni%mods;
      }
    }
    n--;
    flag = !flag;
    return *this;
  }

  Poly& mul(const Poly &x, int v) {
    n=x.n, flag=x.flag;
    for (int i=0; i<=n; i++) a[i] = (ll)x.a[i]*v%mods;
    return *this;
  }

  Poly& mul(const Poly &x, const Poly &y) {
    if (!(x.flag && y.flag)) printf("Err1!\n");
    n = max(x.n, y.n);
    for (int i=0; i<=n; i++) {
      a[i] = (ll)x.a[i]*y.a[i]%mods;
    }
    return *this;
  }

  Poly& dec(const Poly &x, const Poly &y) {
    n = max(x.n, y.n);
    for (int i=0; i<=n; i++) {
      a[i] = (ll)(x.a[i]+mods-y.a[i])%mods;
    }
    return *this;
  }

  Poly& inv(int n, const Poly &x) {
    if (n>1) {
      static Poly c, d, e;
      c.cpy(d.cpy(inv((n+1)/2, x))).ntt(n);
      e.cpy(x).ntt(n);
      dec(d.mul(d, 2), c.mul(c.mul(c, c), e).ntt());
    } else {
      a[0] = qpower(x.a[0], mods-2);
    }
    this->n = n;
    return *this;
  }

  Poly& div(const Poly &a, const Poly &b) {
    static Poly temp[3];
    int n=a.n, m=b.n;
    temp[0].cpy(a).revert().ntt(n-m), temp[1].cpy(b).revert();
    temp[2].inv(n-m, temp[1]).ntt(n-m);
    mul(temp[0], temp[2]).ntt().revert();
    this->n = n-m;
    return *this;
  }

  Poly& mod(const Poly &a, const Poly &b, const Poly &d) {
    static Poly temp[3];
    temp[0].cpy(b).ntt(b.n+d.n), temp[1].cpy(d).ntt(b.n+d.n);
    dec(a, temp[0].mul(temp[0], temp[1]).ntt());
    this->n = b.n-1;
    return *this;
  }
};

int main() {
#ifdef DEBUG
  freopen("src.in", "r", stdin);
  freopen("src.out", "w", stdout);
#endif

  static Poly a, b, d, r;
  scanf("%d %d", &a.n, &b.n);
  for (int i=0; i<=a.n; i++) {
    scanf("%d", a.a+i);
  }
  for (int j=0; j<=b.n; j++) {
    scanf("%d", b.a+j);
  }

  r.mod(a, b, d.div(a, b));

  for (int i=0; i<=d.n; i++) {
    printf("%d ", d.a[i]);
  }
  printf("\n");
  for (int i=0; i<=r.n; i++) {
    printf("%d ", r.a[i]);
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
